<script language="javascript">
    $(document).ready(function() {
        $('#data_cliente').dataTable( {
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "oLanguage": {
                "sLengthMenu": "Mostrar _MENU_ tareas por pagina",
                "sZeroRecords": "Ningun tarea encontrada :(",
                "sInfo": "Mostrando _START_ a _END_ de _TOTAL_ tareas",
                "sInfoEmpty": "Mostrando 0 a 0 de 0 tareas",
                "sInfoFiltered": "(Filtrando de _MAX_ tareas)"
            }
        } );
    } );
</script>

<article class="module width_full">
    <header><h3><b>Mis</b> Tareas</h3></header>
    <div class="module_content">
        <article class="breadcrumbs_content">
            <a href="<?php echo $this->url(array('action' => 'addtarea')) ?>">Agregar Tarea</a>
        </article>

        <table cellpadding="0" cellspacing="0" border="0" class="display" id="data_cliente" width="100%">
            <thead>
                <tr>
                    <th>Titulo</th>
                    <th>Usuario</th>
                    <th>Dias Faltantes</th>
                    <th>Fecha Finalizacion</th>
                    <th>Estado</th>
                    <th>Acciones</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($this->row as $tarea) : ?>
                    <?php
                    $users = new User_Model_DbTable_User();
                    $user = $users->fetchRow("id = " . $tarea->id_user_assigned);

                    $date2 = $tarea->end_date;
                    $date1 = date('Y-m-d');

                    $diff = abs(strtotime($date2) - strtotime($date1));

                    $years = floor($diff / (365 * 60 * 60 * 24));
                    $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
                    $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));
                    ?>
                    <tr>
                        <td><?php echo $tarea->title; ?></td>
                        <td><?php echo $user['nombre'] . ' ' . $user['apellidos'] ?></td>
                        <td><?php echo $months, " Meses - ", $days, " dias"; ?></td>
                        <td><?php echo date('d-m-Y', strtotime($tarea->end_date)) ?></td>
                        <td><?php if ($tarea->status == 1) echo "Terminado"; else echo "En progreso"; ?></td>
                        <td class="center">
                            <a href="<?php echo $this->url(array('action' => 'viewtarea', 'id' => $tarea->id)) ?>">
                                ver
                            </a>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</article>